package org.rsbot.event.impl;

import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Paint;
import java.awt.Point;
import java.awt.RadialGradientPaint;
import java.awt.Rectangle;
import java.awt.RenderingHints;
import java.awt.geom.Point2D.Double;
import java.util.ArrayList;
import org.rsbot.bot.Bot;
import org.rsbot.client.Client;
import org.rsbot.client.input.Mouse;
import org.rsbot.event.listeners.PaintListener;

public class DrawMouse
  implements PaintListener
{
  private Client client;
  private MouseTrailing mouseTrailing = new MouseTrailing();
  private ArrayList<Mouses> Click = new ArrayList();

  public DrawMouse(Bot paramBot) {
    this.client = paramBot.getClient();
  }

  public void onRepaint(Graphics paramGraphics) {
    Mouse localMouse = this.client.getMouse();
    Point localPoint;
    if (localMouse != null) {
      localPoint = new Point(localMouse.getX(), localMouse.getY());
      if ((localMouse.isPressed()) && 
        (this.Click.size() <= 5))
        this.Click.add(new Mouses(System.currentTimeMillis(), localPoint));
      this.mouseTrailing.draw((Graphics2D)paramGraphics, Color.red);
      paramGraphics.setColor(Color.GREEN);
      paramGraphics.drawLine(localPoint.x - 5, localPoint.y, localPoint.x + 5, localPoint.y);

      paramGraphics.drawLine(localPoint.x, localPoint.y - 5, localPoint.x, localPoint.y + 5);

      if (this.Click.size() > 1)
        for (Mouses localMouses : this.Click) {
          if ((localMouse.isPressed()) && 
            (this.Click.size() <= 5)) {
            this.Click.add(new Mouses(System.currentTimeMillis(), localPoint));
          }
          if (System.currentTimeMillis() - localMouses.getTime() < 1000L) {
            paramGraphics.setColor(Color.red);
            paramGraphics.drawLine(localMouses.getLocation().x - 5, localMouses.getLocation().y, localMouses.getLocation().x + 5, localMouses.getLocation().y);

            paramGraphics.drawLine(localMouses.getLocation().x, localMouses.getLocation().y - 5, localMouses.getLocation().x, localMouses.getLocation().y + 5);
          }
          else if (System.currentTimeMillis() - localMouses.getTime() >= 1000L) {
            this.Click.remove(localMouses);
          }
        }
    }
  }

  private class Mouses
  {
    private long Time;
    private Point Location;

    public Mouses(long arg2, Point arg4)
    {
      this.Time = ???;
      Object localObject;
      this.Location = localObject;
    }

    public long getTime() {
      return this.Time;
    }

    public Point getLocation() {
      return this.Location;
    }
  }

  public class MouseTrailing
  {
    private int LifeTime = 1500;
    private ArrayList<DrawMouse.Mouses> Info = new ArrayList();

    public MouseTrailing() {  }

    private void getLocation() { Point localPoint = new Point(DrawMouse.this.client.getMouse().getX(), DrawMouse.this.client.getMouse().getY());

      if (Add(localPoint))
        this.Info.add(new DrawMouse.Mouses(DrawMouse.this, System.currentTimeMillis(), localPoint));
    }

    public boolean Add(Point paramPoint)
    {
      for (DrawMouse.Mouses localMouses : this.Info)
        if (localMouses.getLocation().equals(paramPoint))
          return false;
      return true;
    }

    public void draw(Graphics2D paramGraphics2D, Color paramColor) {
      getLocation();
      paramGraphics2D.setRenderingHints(new RenderingHints(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON));

      if (this.Info.size() > 1)
        for (DrawMouse.Mouses localMouses : this.Info) {
          int i = (int)(localMouses.getTime() + this.LifeTime - System.currentTimeMillis()) / 100;

          if (i >= 2) {
            Rectangle localRectangle = new Rectangle(localMouses.getLocation().x - i / 2, localMouses.getLocation().y - i / 2, i, i);

            Paint localPaint = paramGraphics2D.getPaint();
            RadialGradientPaint localRadialGradientPaint = new RadialGradientPaint(new Point2D.Double(localRectangle.x + localRectangle.width / 2.0D, localRectangle.y + localRectangle.height / 2.0D), (float)(localRectangle.getWidth() / 2.0D), new float[] { 0.0F, 1.0F }, new Color[] { new Color(paramColor.getRed(), paramColor.getGreen(), paramColor.getBlue(), 40), new Color(0.0F, 0.0F, 0.0F, 0.4F) });

            paramGraphics2D.setPaint(localRadialGradientPaint);
            paramGraphics2D.fillRoundRect(localRectangle.x, localRectangle.y, localRectangle.width, localRectangle.height, localRectangle.width, localRectangle.height);

            paramGraphics2D.setPaint(localPaint);
          }
        }
      if ((this.Info.size() > 1) && 
        (System.currentTimeMillis() > ((DrawMouse.Mouses)this.Info.get(0)).getTime() + 1000L))
        this.Info.remove(0);
    }
  }
}